import {USER_LOGIN , INIT_USER} from "./mutations-types.js"
export default{
	state:{
		//登录状态
		loginStatus:false,
		//token
		token:null,
		//用户信息：用户的头像| 用户昵称
		userInfor:{
			
		}
	},
	getters:{
		
	},
	mutations:{
		//设置
		[USER_LOGIN](state, user){
			state.loginStatus = true;
			state.token = user.token;
			state.userInfor = user;
			
			//持久化存储=》本地存储
			localStorage.setItem('teaUseraInfor', JSON.stringify(user))
		},
		
		//读取
		[INIT_USER](state){
			let userInfor = JSON.parse(localStorage.getItem("teaUseraInfor"))
			if(userInfor){
				state.loginStatus = true;
				state.token = userInfor.token;
				state.userInfor = userInfor;
			}
		},
		
		//推出登录，清除本地存储
		loginOut(state){
			state.loginStatus = false;
			state.token = null;
			state.userInfor = {};
			localStorage.removeItem("teaUseraInfor")
		}
	},
	actions:{
		
	}
}